#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
	unsigned int zero=0;
	unsigned int one=1;
	unsigned long arg=0;
	unsigned long *arg1[]={0,1,2,3};
	unsigned long **p=arg1;
	int fd;
	char *array[]={"0","1","2","3","4"};
	char **flag=array;

	if(argc==3){
		int fd=open("/dev/leds",1);
		if(fd<0){
				perror("open LED device:");
				return 1;
		}

	
			while(strcmp("4",*flag)!=0)
			{
							if (  (strcmp(argv[1],*flag)==0)&&(strcmp(argv[2],"on")==0) )
							{
								int val=ioctl(fd,one,*p);
									if(val>0)
									{
										printf("__OK__\n");

									}

									else
									{
										perror("set LED device:");
									}

									return 0;
							}

							else{
									if (  (strcmp(argv[1],*flag)==0)&&(strcmp(argv[2],"off")==0) )
										{
											int val=ioctl(fd,zero,*p);
												if(val>0)
												{
													printf("__OK__\n");

												}
												else
												{
													perror("set LED device:");
												}

												return 0;
										}


								}
						*flag++;
						p++;

				}


				printf("you input error\n");

		

	}


	else{
			if(argc>=2)
                                {
                                 printf("you input error\n");
                                return 0;
                                }

 				
				int fd=open("/dev/leds",1);
			if(fd<0){
				perror("open LED device:");
				return 1;
			}

			for(;;){
				int val=ioctl(fd,one,arg);
				if(val>0){
					printf("__OK__\n");

				}else{
					perror("set LED device:");
				}

				usleep(1*100000);

				int val1=ioctl(fd,zero,arg);
				if(val1>0){
					printf("__OK__\n");

				}
                                else{
					perror("set LED device:");
				}
				usleep(1*100000);

				printf("arg=:%d\n",arg);
				arg++;
				if(arg==4)
				{
					arg=0;
				}
				
			}
		}

	close(fd);
}
